package com.neu.envprotection.feedback.controller;

import com.neu.envprotection.common.constant.SystemConfigConsts;
import com.neu.envprotection.common.resp.PageRespDto;
import com.neu.envprotection.common.resp.RestResp;


import com.neu.envprotection.feedback.dao.entity.City;
import com.neu.envprotection.feedback.dao.entity.Provience;
import com.neu.envprotection.feedback.dao.entity.Rank;
import com.neu.envprotection.feedback.dto.req.*;
import com.neu.envprotection.feedback.dto.resp.FeedbackRespDto;
import com.neu.envprotection.feedback.dto.resp.SupervisorPersonalInfoRespDto;
import com.neu.envprotection.feedback.service.SupervisorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监督员模块
 */

@RestController
@RequestMapping("/api/supervisor")
@RequiredArgsConstructor
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@Tag(name = "用户管理端接口")
@Slf4j

public class SupervisorController {
    @Autowired
    private SupervisorService supervisorService;

    @GetMapping("/selectProvince")
    @Operation(summary = "测试显示所有可选省")
    private RestResp<List<Provience>> showAllProvince(){
        return supervisorService.showAllProvince();
    }

    @GetMapping("/selectCity/{provinceId}")
    @Operation(summary = "测试显示所有可选市")
    private RestResp<List<City>> showCitiesRingP(@PathVariable Integer provinceId){
        return supervisorService.showCitiesRingP(provinceId);
    }

    @PostMapping("/feedbackAdd")
    @Operation(summary = "存入用户选择的网格以及监督信息")
    private RestResp<Void> feedbackAdd(@RequestBody SupervisorFeedbackAddReqDto supervisorFeedbackAddReqDto){
        System.out.println(supervisorFeedbackAddReqDto.getFDateTime());
        supervisorService.insertFeedback(supervisorFeedbackAddReqDto);
        return null;
    }

    @PostMapping("/specificGrid")
    @Operation(summary = "输入具体地址并将省市地址存入数据库")
    private RestResp<Void> insertSpecificGrid(SupervisorSpecificGridReqDto supervisorSpecificGridReqDto){
        supervisorService.insertSpecificGrid(supervisorSpecificGridReqDto);
        return null;
    }

    @GetMapping("/selectAPI")
    @Operation(summary = "向监督员展示所有API等级")
    private RestResp<List<Rank>> showAllRanks(){
        return supervisorService.showAllRanks();
    }



    @PostMapping("/feedbackBySidByPage")
    @Operation(summary = "监督者查看所有历史反馈信息")
    private RestResp<PageRespDto<FeedbackRespDto>> viewFeedback(@RequestBody SupervisorFeedbackViewReqDto supervisorFeedbackViewReqDto){
        //System.out.println(supervisorFeedbackViewReqDto.getSId()+"   "+supervisorFeedbackViewReqDto.getPageNum()+"   "+supervisorFeedbackViewReqDto.getPageSize());
        //return supervisorService.viewFeedback(supervisorFeedbackViewReqDto);
        //return supervisorService.viewFeedback(userId);
        return supervisorService.viewFeedback(supervisorFeedbackViewReqDto);
    }

    @GetMapping("/personalInfo/{userId}")
    @Operation(summary = "监督者查看个人信息")
    private RestResp<SupervisorPersonalInfoRespDto> getPersonalInfo(@PathVariable Integer userId){
        return supervisorService.getPersonalInfo(userId);
    }

    @PostMapping("/updateInfo")
    @Operation(summary = "监督者修改个人信息")
    private RestResp<Void> viewFeedback(@RequestBody SupervisorUpdateReqDto supervisorUpdateReqDto){
        return supervisorService.updateInfo(supervisorUpdateReqDto);
    }

    @PostMapping("/updatePassword")
    @Operation(summary = "监督者修改密码")
    private RestResp<Void> viewFeedback(@RequestBody SupervisorUpdatePwdReqDto supervisorUpdatePwdReqDto){
        return supervisorService.updatePassword(supervisorUpdatePwdReqDto);
    }
}
